﻿
@page "/Bas/CodingRule/Edit"
@using nERP.ViewModel.Bas.CodingRuleVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<div>
  <ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit" >
    <Row ItemsPerRow="ItemsPerRow.Two" RowType="RowType.Normal">
      <Select @bind-Value="@Model.Entity.CodingListId" Items="AllCodingLists" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="gab4a0333dcec4cfdb8398358da550a06"/>
      <BootstrapInput @bind-Value="@Model.Entity.Seq"/>
      <Select @bind-Value="@Model.Entity.CodeRule" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g28542ff1cf33483781843445a70e6e15"/>
      <BootstrapInput @bind-Value="@Model.Entity.FixedValue"/>
      <Select @bind-Value="@Model.Entity.FixedRule" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g6d879d2e7cb84f0cb9b6dcdbf068030c"/>
      <BootstrapInput @bind-Value="@Model.Entity.GlideLen"/>
      <BootstrapInput @bind-Value="@Model.Entity.StartNumber"/>
      <BootstrapInput @bind-Value="@Model.Entity.GlideStep"/>
      <BootstrapInput @bind-Value="@Model.Entity.Glide"/>
    </Row>

    <div class="modal-footer table-modal-footer">
      <Button ButtonType="ButtonType.Submit" IsAsync="true" Text="@WtmBlazor.Localizer["Sys.Submit"]"/>
      <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]"/>
    </div>

  </ValidateForm>

</div>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private CodingRuleVM Model = new CodingRuleVM();
    private ValidateForm vform { get; set; }
    private async Task Submit(EditContext context)
    {
                        
        
        await PostsForm(vform, "/api/Bas/CodingRule/Edit", (s) => "Sys.OprationSuccess", method: HttpMethodEnum.PUT);
    }
    public void OnClose()
    {
        CloseDialog();
    }
    
    private List<SelectedItem> AllCodingLists = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {
        
        
        AllCodingLists = await WtmBlazor.Api.CallItemsApi("/api/Bas/CodingRule/GetCodingLists");
        AllCodingLists.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"],Value = "" });
        if (id != "")
        {
            var rv = await WtmBlazor.Api.CallAPI<CodingRuleVM>($"/api/Bas/CodingRule/{id}");
            Model = rv.Data;
        }

        await base.OnInitializedAsync();
    }
}
